package com.reder.practice.controller;

import com.reder.practice.common.annotation.FromSession;
import com.reder.practice.bean.User;
import com.reder.practice.bean.Video;
import com.reder.practice.common.dto.ServerResponse;
import com.reder.practice.common.util.PageUtil;
import com.reder.practice.service.VideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 视频web层
 *
 * @author Red
 * <p>Email: 1318944013@qq.com</p>
 * <p>created by 2019/09/23 15:11</p>
 */
@RestController
public class VideoController {

    @Resource
    private VideoService videoService;

    @PostMapping("/video")
    @ApiOperation("上传视频")
    public ServerResponse addVideo(@RequestParam("file") MultipartFile file,
                                   Video video, @FromSession User user) {
        return videoService.addVideo(file, video, user);
    }

    @GetMapping("/videos")
    @ApiOperation("展示视频列表")
    public ServerResponse listVideo(int pageNumber,
                                    @RequestParam(defaultValue = PageUtil.DEFAULT_SIZE_OF_ONE_PAGE + "") int sizeOfOnePage) {

        return videoService.listVideo(pageNumber, sizeOfOnePage);
    }


    @PutMapping("/video")
    @ApiOperation("更新视频信息")
    public ServerResponse updateVideo(Video video) {

        return videoService.updateVideo(video);
    }

    @DeleteMapping("/video/{videoId}")
    @ApiOperation("删除视频")
    public ServerResponse deleteVideo(@PathVariable("videoId") long videoId) {
        return videoService.deleteVideo(videoId);
    }
}
